package com.company.project.web;
import com.company.project.core.Result;
import com.company.project.core.ResultGenerator;
import com.company.project.model.League;
import com.company.project.service.LeagueService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
* Created by CodeGenerator on 2018/10/08.
*/
@RestController
@RequestMapping("/league")
public class LeagueController {
    @Resource
    private LeagueService leagueService;

    /**
     * 查询期刊加盟
     * @return
     */
    @RequestMapping(value = "/selectleague",method = RequestMethod.GET,produces = "application/json;charset=UTF-8")
    @ResponseBody
    public List<League> selectLeague(){
        List<League> list = leagueService.selectLeague();
        return list;
    }

    /**
     * 修改期刊加盟
     * @param league
     * @return
     */
    @PostMapping("/updateleague")
    @ResponseBody
    public Result updateleague(@RequestBody League league){
        Boolean updateleague = leagueService.updateleague(league);
        return ResultGenerator.genSuccessResult(updateleague);
    }
    @PostMapping("/add")
    public Result add(League league) {
        leagueService.save(league);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/delete")
    public Result delete(@RequestParam Integer id) {
        leagueService.deleteById(id);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/update")
    public Result update(League league) {
        leagueService.update(league);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/detail")
    public Result detail(@RequestParam Integer id) {
        League league = leagueService.findById(id);
        return ResultGenerator.genSuccessResult(league);
    }

    @PostMapping("/list")
    public Result list(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "0") Integer size) {
        PageHelper.startPage(page, size);
        List<League> list = leagueService.findAll();
        PageInfo pageInfo = new PageInfo(list);
        return ResultGenerator.genSuccessResult(pageInfo);
    }
}
